package service

import (
	dao "gorm_demo/pkg/dao"
	models "gorm_demo/pkg/models"
	repo "gorm_demo/pkg/repo"
)

type AuthUserService interface {
	List() (l []*models.AuthUser)
	GetById(id int32) (*models.AuthUser, error)
	Create(m models.AuthUser) (*models.AuthUser, error)
	Update(m models.AuthUser, updates map[string]interface{}) (*models.AuthUser, error)
	Delete(m models.AuthUser) error
}

func NewAuthUserRepository() repo.AuthUserRepository {
	return dao.AuthUserDao{}
}

type AuthuserService struct {
	repo repo.AuthUserRepository
}

func NewAuthUserService(repo repo.AuthUserRepository) AuthUserService {
	return &AuthuserService{
		repo: repo,
	}
}

func (svc *AuthuserService) Delete(m models.AuthUser) error { return svc.repo.Delete(m) }

func (svc *AuthuserService) List() []*models.AuthUser { return svc.repo.List() }

func (svc *AuthuserService) GetById(id int32) (*models.AuthUser, error) { return svc.repo.GetById(id) }

func (svc *AuthuserService) Create(u models.AuthUser) (*models.AuthUser, error) {
	return svc.repo.Create(u)
}

func (svc *AuthuserService) Update(u models.AuthUser, updates map[string]interface{}) (*models.AuthUser, error) {
	return svc.repo.Update(u, updates)
}
